<div class="content-wrapper">
    <section class="content-header">
        <h1>订单管理</h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">订单管理</li>
            <li class="active"><a href="/admin/Order/orderList">列表</a></li>
            <li class="active">受理下单</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
            </div>
            <div class="box-body">
                <form class="form-horizontal" role="form" action="javascrip:;" method="post">
                    <input type="hidden" name="id" id="id" value="{$orderInfo.order_id}" />
                    <div class="form-group">
                        <label for="order_time" class="col-sm-3 control-label"> 下单时间： </label>
                        <div class="col-sm-6">
                            {$orderInfo['order_time']}
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="admin_name" class="col-sm-3 control-label"> 部门人员： </label>
                        <div class="col-sm-6">
                            {$orderInfo.admin_name}
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="order_code" class="col-sm-3 control-label"> 订单编号： </label>
                        <div class="col-sm-6">
                            {$orderInfo.order_code}
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="department_name" class="col-sm-3 control-label"> 部门： </label>
                        <div class="col-sm-6">
                            {$orderInfo.department_name}
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="protocol_number" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 协议号： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="protocol_number" name="protocol_number" value="{$orderInfo.protocol_number}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_pay" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 是否到款： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" value="{$orderInfo['is_pay'] == 1 ? '是' : '否'}" placeholder="是否到款" disabled>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="company_name" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 终端客户名称： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="company_name" name="company_name" value="{$orderInfo.company_name}" placeholder="科技公司">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 联系人： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name" value="{$orderInfo.name}" placeholder="景海霞">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="quoted_price" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 支付金额： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="quoted_price" name="quoted_price" value="{$orderInfo.quoted_price}" placeholder="支付金额">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="recharge_price" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 账户充值金额： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="recharge_price" name="recharge_price" value="{$orderInfo.recharge_price}" placeholder="账户充值金额">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="user_name" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 用户名： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="user_name" name="user_name" value="{$orderInfo.user_name}" placeholder="用户名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="contract_number" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 供应商合同号： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="contract_number" name="contract_number" value="{$orderInfo.contract_number}" placeholder="供应商合同号">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="pay_interval" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 账期： </label>
                        <div class="col-sm-6">
                            <input type="text" id="pay_interval" class="form-control" value="{$orderInfo.pay_interval}" placeholder="2个月">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="agent_name" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 公司名（代理商）： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="agent_name" name="agent_name" value="{$orderInfo.agent_name}" placeholder="网易科技">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="ditch_company" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 渠道公司: </label>
                        <div class="col-sm-6">
                            <input id="ditch_company" name="ditch_company" class="form-control" type="text" value="{$orderInfo.ditch_company}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="forecast_time" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 预计到款时间: </label>
                        <div class="col-sm-6">
                            <input id="forecast_time" name="forecast_time" class="form-control datepicker" type="text" placeholder="预计到款时间" value="{$orderInfo.forecast_time}" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="mobile" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 联系方式： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="mobile" name="mobile" value="{$orderInfo.mobile}" placeholder="17989898989">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="product_name" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 项目： </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="product_name" name="product_name" value="{$orderInfo.product_name}" placeholder="原生广告">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="amount" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 销售金额 </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="amount" name="amount" value="{$orderInfo.amount}" placeholder="销售金额">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="rebate" class="col-sm-3 control-label"><span style="color: #f00;">*</span> 客户享受返点 </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="rebate" name="rebate" value="{$orderInfo.rebate}" placeholder="40%">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="mobile" class="col-sm-3 control-label">备注 </label>
                        <div class="col-sm-6">
                            <textarea name="remark" id="remark" class="form-control" rows="5">{$orderInfo.remark}</textarea>
                        </div>
                    </div>

                    <hr style="margin: 50px auto;border-bottom: 1px #dcdcdc solid;"/>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="is_filing" class="col-sm-3 control-label"> 合同： </label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="is_filing" id="is_filing">
                                        <option value="0" {$orderInfo['is_filing'] == 0 ? 'selected' : ''}>未归档</option>
                                        <option value="1" {$orderInfo['is_filing'] == 1 ? 'selected' : ''}>已归档</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="is_bill" class="col-sm-3 control-label"> 发票： </label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="is_bill" id="is_bill">
                                        <option value="0" {$orderInfo['is_bill'] == 0 ? 'selected' : ''}>未开</option>
                                        <option value="1" {$orderInfo['is_bill'] == 1 ? 'selected' : ''}>已开</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="is_pay" class="col-sm-3 control-label"> 款项： </label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="is_pay" id="is_pay">
                                        <option value="0" {$orderInfo['is_pay'] == 0 ? 'selected' : ''}>未到帐</option>
                                        <option value="1" {$orderInfo['is_pay'] == 1 ? 'selected' : ''}>已到帐</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="pay_company" class="col-sm-3 control-label"> 付款公司： </label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="pay_company" name="pay_company" value="{$orderInfo.pay_company}" placeholder="请填写公司名称">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="pay_company" class="col-sm-3 control-label"> 到款金额： </label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="pay_amount" name="pay_amount" value="{$orderInfo.pay_amount}" placeholder="请填写到账金额">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="pay_time" class="col-sm-3 control-label"> 到款时间： </label>
                                <div class="col-sm-8">
                                    <input type="text" readonly class="form-control pull-right datepicker" id="pay_time" name="pay_time" value="{$orderInfo['pay_time']}" placeholder="请填写到账时间">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="account_company" class="col-sm-3 control-label"> 入账公司： </label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="account_company" name="account_company" value="{$orderInfo.account_company}" placeholder="请填写公司名称">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group" style="margin: 30px auto;">
                        <label for="form-field-1" class="col-sm-3 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-info btn-sm save-btn">提交保存</button>
                            &nbsp;
                            <button type="reset" class="btn btn-sm">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<script type="application/javascript">
    $(function () {
        $('.datepicker').datepicker({
            autoclose : true,
            format : 'yyyy-mm-dd'
        });
    });
    //保存用户
    $(".save-btn").click(function(){
        var preg = /^1[34578]\d{9}$/; //手机号
        var id = $("#id").val();
        var name = $.trim($("#name").val());
        var company_name = $("#company_name").val();
        var agent_name = $("#agent_name").val();
        var amount = $("#amount").val();
        var mobile = $("#mobile").val();
        var protocol_number = $('#protocol_number').val();
        var product_name = $('#product_name').val();
        var quoted_price = $('#quoted_price').val();
        var pay_interval = $('#pay_interval').val();
        var rebate = $('#rebate').val();
        var remark = $('#remark').val();
        var is_filing = $('#is_filing').val();
        var is_bill = $('#is_bill').val();
        var is_pay = $('#is_pay').val();
        var pay_company = $('#pay_company').val();
        var ditch_company = $('#ditch_company').val();
        var pay_amount = $('#pay_amount').val();
        var pay_time = $('#pay_time').val();
        var recharge_price = $('#recharge_price').val();
        var user_name = $('#user_name').val();
        var contract_number = $('#contract_number').val();
        var forecast_time = $('#forecast_time').val();
        var account_company = $('#account_company').val();

        if(name == '') {
            layer.msg('请填写联系人',{time: 1000});
            $("#name").focus();
            return false;
        }
        if(company_name == ''){
            layer.msg('请填写公司名称',{time: 1000});
            $("#company_name").focus();
            return false;
        }
        if(product_name == ''){
            layer.msg('请填写项目名称',{time: 1000});
            $("#product_name").focus();
            return false;
        }
        if(!preg.test(mobile)){
            layer.msg('手机号不存在，请重新输入',{time: 1000});
            $("#mobile").focus();
            return false;
        }
        if(agent_name == ''){
            layer.msg('请填写代理商名称',{time: 1000});
            $("#company").focus();
            return false;
        }
        if(ditch_company == ''){
            layer.msg('请填写渠道公司名称',{time: 1000});
            $("#ditch_company").focus();
            return false;
        }
        if(forecast_time == ''){
            layer.msg('请填写预计到款时间',{time: 1000});
            $("#forecast_time").focus();
            return false;
        }
        if(recharge_price == '' || isNaN(recharge_price)){
            layer.msg('请填写账户充值金额',{time: 1000});
            $("#recharge_price").focus();
            return false;
        }
        if(user_name == ''){
            layer.msg('请填写用户名',{time: 1000});
            $("#user_name").focus();
            return false;
        }
        if(contract_number == ''){
            layer.msg('请填写供应商合同号',{time: 1000});
            $("#contract_number").focus();
            return false;
        }
        if(amount == '' || isNaN(amount)){
            layer.msg('请填写销售金额',{time: 1000});
            $("#amount").focus();
            return false;
        }
        if(protocol_number == ''){
            layer.msg('请填写协议号',{time: 1000});
            $("#protocol_number").focus();
            return false;
        }
        if(quoted_price == '' || isNaN(quoted_price)){
            layer.msg('请填写支付金额',{time: 1000});
            $("#quoted_price").focus();
            return false;
        }
        if(rebate == '' || isNaN(rebate)){
            layer.msg('请填写客户享受返点',{time: 1000});
            $("#rebate").focus();
            return false;
        }
        if(is_pay==1 &&  pay_company == ''){
            layer.msg('请填写支付公司名称',{time: 1000});
            $("#pay_company").focus();
            return false;
        }
        if(is_pay==1 && (pay_amount == '' || isNaN(pay_amount))){
            layer.msg('请填写到账金额',{time: 1000});
            $("#pay_amount").focus();
            return false;
        }
        if(is_pay==1 &&  pay_time == ''){
            layer.msg('请填写到账时间',{time: 1000});
            $("#pay_time").focus();
            return false;
        }


        $.post('/admin/Order/ajaxSaveOrder',
                {
                    id : id,
                    name :name,
                    company_name : company_name,
                    agent_name : agent_name,
                    account_company : account_company,
                    ditch_company : ditch_company,
                    amount : amount,
                    mobile : mobile,
                    protocol_number : protocol_number,
                    product_name : product_name,
                    quoted_price : quoted_price,
                    rebate : rebate,
                    remark : remark,
                    is_filing : is_filing,
                    is_bill : is_bill,
                    is_pay : is_pay,
                    pay_company : pay_company,
                    pay_amount : pay_amount,
                    pay_time : pay_time,
                    pay_interval : pay_interval,
                    recharge_price : recharge_price,
                    user_name : user_name,
                    contract_number : contract_number,
                    forecast_time : forecast_time
                }, function(data){
                    if(data.Code == 999) {
                        layer.alert('操作成功', {
                            skin: 'layui-layer-molv' //样式类名
                            ,closeBtn: 0
                        }, function(){
                            window.location.reload(true);
                            //window.location.href = '/admin/order/orderList';
                        });
                    } else {
                        layer.alert(data.Msg, {
                            skin: 'layui-layer-molv' //样式类名
                            ,closeBtn: 0
                        });
                    }
                }, 'json');
    });
</script>